﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MODULE_QUANTRIHETHONG
{
    public partial class frm_doimatkhau : Form
    {
        hethongDataContext context=cls_quantrihethong.getcontext();
        private string username;
        public string _username
        {
            set { this.username = value; }
            get { return username; }
        }
        public frm_doimatkhau()
        {
            InitializeComponent();
        }
        private bool funcvalidate()
        {
            bool kq=true;
            string password=this.txtpassword.Text;
            string confimpassword=this.txtconfimpassword.Text;
            if(password!=confimpassword)
            {
                kq=false;
            }
            return kq;
        }
        private void frm_doimatkhau_Load(object sender, EventArgs e)
        {
         
          
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string username = cls_quantrihethong.tendangnhap;
                string password = this.txtpassword.Text;
                if (funcvalidate() == true)
                {
                    IEnumerable<DM_nhanvien> nhanviens = from c in context.DM_nhanviens where c.username.Equals(username) select c;
                    if (nhanviens.Count() > 0)
                    {
                        foreach (DM_nhanvien nv in nhanviens)
                        {
                            nv.password = mycryptography.cls_mycryptography.EncryptString("daiviet", password);
                        }
                        context.SubmitChanges();
                        MessageBox.Show("Cập nhật thành công");
                    }



                }
                else
                {
                    MessageBox.Show("Password chưa so khớp.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Không cập nhật được.Lỗi" + ex.Message);
            }
        }

        private void txtconfimpassword_TextChanged(object sender, EventArgs e)
        {
            string confim = this.txtconfimpassword.Text;
            string pass = this.txtpassword.Text;
            if (confim == pass)
            {
                btOK.Enabled = true;
            }
            else
            {
                btOK.Enabled = false;
            }
        }
    }
}
